from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-26 14:02:23.402270
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 26, Aug, 2022
Time: 14:02:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2147
Nobs: 760.000 HQIC: -50.5521
Log likelihood: 9674.55 FPE: 8.98963e-23
AIC: -50.7634 Det(Omega_mle): 7.99186e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300103 0.054921 5.464 0.000
L1.Burgenland 0.106842 0.036523 2.925 0.003
L1.Kärnten -0.106632 0.019395 -5.498 0.000
L1.Niederösterreich 0.206246 0.076283 2.704 0.007
L1.Oberösterreich 0.112113 0.074006 1.515 0.130
L1.Salzburg 0.252818 0.039060 6.473 0.000
L1.Steiermark 0.036696 0.050967 0.720 0.472
L1.Tirol 0.107106 0.041250 2.597 0.009
L1.Vorarlberg -0.060460 0.035467 -1.705 0.088
L1.Wien 0.049974 0.065793 0.760 0.448
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061519 0.114130 0.539 0.590
L1.Burgenland -0.034526 0.075897 -0.455 0.649
L1.Kärnten 0.047208 0.040303 1.171 0.241
L1.Niederösterreich -0.174345 0.158519 -1.100 0.271
L1.Oberösterreich 0.396947 0.153788 2.581 0.010
L1.Salzburg 0.289678 0.081169 3.569 0.000
L1.Steiermark 0.104556 0.105912 0.987 0.324
L1.Tirol 0.314402 0.085720 3.668 0.000
L1.Vorarlberg 0.026701 0.073703 0.362 0.717
L1.Wien -0.024716 0.136721 -0.181 0.857
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190920 0.028243 6.760 0.000
L1.Burgenland 0.089367 0.018782 4.758 0.000
L1.Kärnten -0.008693 0.009974 -0.872 0.383
L1.Niederösterreich 0.259529 0.039229 6.616 0.000
L1.Oberösterreich 0.134951 0.038058 3.546 0.000
L1.Salzburg 0.045773 0.020087 2.279 0.023
L1.Steiermark 0.017411 0.026210 0.664 0.506
L1.Tirol 0.093640 0.021213 4.414 0.000
L1.Vorarlberg 0.058329 0.018239 3.198 0.001
L1.Wien 0.119859 0.033834 3.543 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107506 0.028676 3.749 0.000
L1.Burgenland 0.046951 0.019070 2.462 0.014
L1.Kärnten -0.014620 0.010126 -1.444 0.149
L1.Niederösterreich 0.192428 0.039829 4.831 0.000
L1.Oberösterreich 0.290276 0.038640 7.512 0.000
L1.Salzburg 0.111783 0.020394 5.481 0.000
L1.Steiermark 0.102171 0.026611 3.839 0.000
L1.Tirol 0.110135 0.021538 5.114 0.000
L1.Vorarlberg 0.069625 0.018518 3.760 0.000
L1.Wien -0.017030 0.034352 -0.496 0.620
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130555 0.052093 2.506 0.012
L1.Burgenland -0.051881 0.034642 -1.498 0.134
L1.Kärnten -0.040282 0.018396 -2.190 0.029
L1.Niederösterreich 0.169982 0.072354 2.349 0.019
L1.Oberösterreich 0.141126 0.070195 2.010 0.044
L1.Salzburg 0.288013 0.037049 7.774 0.000
L1.Steiermark 0.032043 0.048342 0.663 0.507
L1.Tirol 0.161748 0.039126 4.134 0.000
L1.Vorarlberg 0.100845 0.033641 2.998 0.003
L1.Wien 0.069821 0.062404 1.119 0.263
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056655 0.041493 1.365 0.172
L1.Burgenland 0.040581 0.027593 1.471 0.141
L1.Kärnten 0.050167 0.014653 3.424 0.001
L1.Niederösterreich 0.220622 0.057631 3.828 0.000
L1.Oberösterreich 0.284124 0.055911 5.082 0.000
L1.Salzburg 0.045684 0.029510 1.548 0.122
L1.Steiermark -0.001619 0.038505 -0.042 0.966
L1.Tirol 0.148230 0.031164 4.756 0.000
L1.Vorarlberg 0.072373 0.026795 2.701 0.007
L1.Wien 0.084056 0.049706 1.691 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180551 0.049688 3.634 0.000
L1.Burgenland -0.005500 0.033043 -0.166 0.868
L1.Kärnten -0.061454 0.017547 -3.502 0.000
L1.Niederösterreich -0.082989 0.069013 -1.203 0.229
L1.Oberösterreich 0.197392 0.066954 2.948 0.003
L1.Salzburg 0.056225 0.035338 1.591 0.112
L1.Steiermark 0.230365 0.046110 4.996 0.000
L1.Tirol 0.493945 0.037319 13.236 0.000
L1.Vorarlberg 0.047551 0.032088 1.482 0.138
L1.Wien -0.053829 0.059523 -0.904 0.366
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166166 0.057063 2.912 0.004
L1.Burgenland -0.011013 0.037947 -0.290 0.772
L1.Kärnten 0.067095 0.020151 3.330 0.001
L1.Niederösterreich 0.206087 0.079257 2.600 0.009
L1.Oberösterreich -0.070104 0.076891 -0.912 0.362
L1.Salzburg 0.211246 0.040583 5.205 0.000
L1.Steiermark 0.115628 0.052954 2.184 0.029
L1.Tirol 0.071654 0.042858 1.672 0.095
L1.Vorarlberg 0.121665 0.036850 3.302 0.001
L1.Wien 0.123182 0.068358 1.802 0.072
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360559 0.032915 10.954 0.000
L1.Burgenland 0.006122 0.021889 0.280 0.780
L1.Kärnten -0.023404 0.011624 -2.013 0.044
L1.Niederösterreich 0.214677 0.045718 4.696 0.000
L1.Oberösterreich 0.192321 0.044353 4.336 0.000
L1.Salzburg 0.045540 0.023410 1.945 0.052
L1.Steiermark -0.017484 0.030545 -0.572 0.567
L1.Tirol 0.105958 0.024722 4.286 0.000
L1.Vorarlberg 0.073085 0.021256 3.438 0.001
L1.Wien 0.044300 0.039431 1.123 0.261
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040286 0.148841 0.192645 0.157830 0.124316 0.112816 0.066203 0.222954
Kärnten 0.040286 1.000000 -0.004107 0.133562 0.040950 0.095744 0.430950 -0.052377 0.100218
Niederösterreich 0.148841 -0.004107 1.000000 0.337240 0.149786 0.299330 0.107508 0.183075 0.322654
Oberösterreich 0.192645 0.133562 0.337240 1.000000 0.227958 0.331566 0.173055 0.167995 0.264970
Salzburg 0.157830 0.040950 0.149786 0.227958 1.000000 0.147290 0.122404 0.147572 0.131771
Steiermark 0.124316 0.095744 0.299330 0.331566 0.147290 1.000000 0.150686 0.138074 0.078939
Tirol 0.112816 0.430950 0.107508 0.173055 0.122404 0.150686 1.000000 0.115024 0.152043
Vorarlberg 0.066203 -0.052377 0.183075 0.167995 0.147572 0.138074 0.115024 1.000000 0.006605
Wien 0.222954 0.100218 0.322654 0.264970 0.131771 0.078939 0.152043 0.006605 1.000000